/* 自动生成的绑定文件 - 建议通过 build.rs + bindgen 动态生成 */
#![allow(non_snake_case, non_camel_case_types, non_upper_case_globals)]

use std::os::raw::{c_char, c_int, c_uchar, c_float};

// 结构体定义 (需保证内存布局与C一致)
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct zint_vector_rect {
    pub x: c_float,
    pub y: c_float,
    pub height: c_float,
    pub width: c_float,
    pub colour: c_int,
    pub next: *mut zint_vector_rect,
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct zint_vector_hexagon {
    pub x: c_float,
    pub y: c_float,
    pub diameter: c_float,
    pub rotation: c_int,
    pub next: *mut zint_vector_hexagon,
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct zint_vector_string {
    pub x: c_float,
    pub y: c_float,
    pub fsize: c_float,
    pub width: c_float,
    pub length: c_int,
    pub rotation: c_int,
    pub halign: c_int,
    pub text: *mut c_uchar,
    pub next: *mut zint_vector_string,
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct zint_vector_circle {
    pub x: c_float,
    pub y: c_float,
    pub diameter: c_float,
    pub width: c_float,
    pub colour: c_int,
    pub next: *mut zint_vector_circle,
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct zint_vector {
    pub width: c_float,
    pub height: c_float,
    pub rectangles: *mut zint_vector_rect,
    pub hexagons: *mut zint_vector_hexagon,
    pub strings: *mut zint_vector_string,
    pub circles: *mut zint_vector_circle,
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct zint_structapp {
    pub index: c_int,
    pub count: c_int,
    pub id: [c_char; 32],
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct zint_symbol {
    pub symbology: c_int,
    pub height: c_float,
    pub scale: c_float,
    pub whitespace_width: c_int,
    pub whitespace_height: c_int,
    pub border_width: c_int,
    pub output_options: c_int,
    pub fgcolour: [c_char; 10],
    pub bgcolour: [c_char; 10],
    pub fgcolor: *mut c_char,
    pub bgcolor: *mut c_char,
    pub outfile: [c_char; 256],
    pub primary: [c_char; 128],
    pub option_1: c_int,
    pub option_2: c_int,
    pub option_3: c_int,
    pub show_hrt: c_int,
    pub fontsize: c_int,
    pub input_mode: c_int,
    pub eci: c_int,
    pub dpmm: c_float,
    pub dot_size: c_float,
    pub guard_descent: c_float,
    pub structapp: zint_structapp,
    pub warn_level: c_int,
    pub debug: c_int,
    pub text: [c_uchar; 128],
    pub rows: c_int,
    pub width: c_int,
    pub encoded_data: [[c_uchar; 144]; 200],
    pub row_height: [c_float; 200],
    pub errtxt: [c_char; 100],
    pub bitmap: *mut c_uchar,
    pub bitmap_width: c_int,
    pub bitmap_height: c_int,
    pub alphamap: *mut c_uchar,
    pub bitmap_byte_length: u32,
    pub vector: *mut zint_vector,
}

// 链接到 zint 库
#[link(name = "zint")]
unsafe extern "C" {     
    pub fn ZBarcode_Create() -> *mut zint_symbol;

    pub fn ZBarcode_Delete(symbol: *mut zint_symbol);

    pub fn ZBarcode_Encode_and_Buffer(symbol: *mut zint_symbol, source: *const c_uchar,  length:c_int,
                         rotate_angle:c_int) -> c_int;
}
